import 'package:flutter/material.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/color.dart';
import 'package:ost_flutter_module/common/utils.dart';

class LoadingErrorWidget extends StatelessWidget {
  final String errorTitle;
  final String retryText;
  final Color backgroundColor;
  final VoidCallback onRetry;

  const LoadingErrorWidget(
      {Key key,
      this.errorTitle,
      this.retryText,
      this.onRetry,
      this.backgroundColor = Colors.white})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      color: backgroundColor,
      child: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Utils.svgAssets('empty'),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: Adapt.px(30)),
              child: Text(
                errorTitle ?? "服务器出错",
                maxLines: 5,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(color: color666666, fontSize: Adapt.px(16)),
              ),
            ),
            SizedBox(height: Adapt.px(6)),
            Text(
              "请稍后重试",
              style: TextStyle(color: colorC9C9C9, fontSize: Adapt.px(14)),
            ),
            SizedBox(height: Adapt.px(16)),
            ButtonTheme(
              minWidth: Adapt.px(130),
              child: MaterialButton(
                onPressed: () {
                  onRetry();
                },
                elevation: Adapt.px(3),
                padding: EdgeInsets.symmetric(vertical: Adapt.px(8)),
                color: colorFACD33,
                child: Text(
                  retryText ?? "重试",
                  style: TextStyle(
                      fontSize: Adapt.px(16),
                      color: Colors.white,
                      fontWeight: FontWeight.w400),
                ),
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(Adapt.px(30))),
              ),
            ),
            SizedBox(height: Adapt.px(80)),
          ],
        ),
      ),
    );
  }
}
